package com.tbs.easyhomemoneyserver.service.impl;

import com.tbs.easyhomemoneyserver.DO.LoginInfo;
import com.tbs.easyhomemoneyserver.DO.SysUser;
import com.tbs.easyhomemoneyserver.dao.LoginInfoDao;
import com.tbs.easyhomemoneyserver.dao.SysUserDao;
import com.tbs.easyhomemoneyserver.form.UserCreateForm;
import com.tbs.easyhomemoneyserver.service.IUserService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements IUserService {
    @Resource
    SysUserDao userDao;


    @Resource
    LoginInfoDao loginInfoDao;

    @Override
    public SysUser newUser(UserCreateForm createForm) {
        if (createForm == null) {
            return null;
        }
        SysUser user = new SysUser();
        user.setName(createForm.getUserName());
        user.setSex(createForm.getSex());
        user.setPhone(createForm.getPhone());
        user.setPassword(createForm.getPassword());
        userDao.insert(user);
        return user;
    }

    @Override
    public SysUser getUserByName(String name) {
        return null;
    }

    @Override
    public SysUser getUserByPhone(String phone) {
        return null;
    }

    @Override
    @Cacheable(value = "user", key = "#id")
    public SysUser getUserById(Long id) {
        return userDao.selectByPrimaryKey(id);
    }

    @Override
    @Cacheable(value = "loginInfo", key = "#id")
    public LoginInfo getLoginInfoByID(Long id) {
        return loginInfoDao.selectByPrimaryKey(id);
    }
}
